<html>
<head><meta charset="utf-8"><title>TypeId guarantees · t-compiler/wg-polymorphization · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/index.html">t-compiler/wg-polymorphization</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html">TypeId guarantees</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206287053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206287053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206287053">(Aug 07 2020 at 17:40)</a>:</h4>
<p>std docs:</p>
<blockquote>
<p>A <code>TypeId</code> represents a globally unique identifier for a type.</p>
</blockquote>
<p>This is somewhat dubious with polymorphization</p>



<a name="206287166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206287166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206287166">(Aug 07 2020 at 17:41)</a>:</h4>
<p>esp now that we start to polymorphize functions which are used in types (in <a href="https://github.com/rust-lang/rust/issues/75255">#75255</a>)</p>



<a name="206290008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206290008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206290008">(Aug 07 2020 at 18:01)</a>:</h4>
<p>A good example of what probably breaks is</p>
<div class="codehilite"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">any</span>::<span class="p">{</span><span class="n">Any</span><span class="p">,</span><span class="w"> </span><span class="n">TypeId</span><span class="p">};</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">collections</span>::<span class="n">HashMap</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">id</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">insert_fn</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">&#39;static</span><span class="o">&gt;</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="n">map</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">HashMap</span><span class="o">&lt;</span><span class="n">TypeId</span><span class="p">,</span><span class="w"> </span><span class="nb">Box</span><span class="o">&lt;</span><span class="k">dyn</span><span class="w"> </span><span class="nb">FnMut</span><span class="p">(</span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="p">())</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="k">mut</span><span class="w"> </span><span class="n">f</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">FnMut</span><span class="p">(</span><span class="o">&amp;</span><span class="n">T</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nb">&#39;static</span><span class="p">,</span><span class="w"></span>
<span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">func</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nb">Box</span>::<span class="n">new</span><span class="p">(</span><span class="k">move</span><span class="w"> </span><span class="o">|</span><span class="n">v</span><span class="o">|</span><span class="w"> </span><span class="n">f</span><span class="p">(</span><span class="o">&amp;*</span><span class="p">(</span><span class="n">v</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="p">)))</span><span class="w"> </span><span class="p">};</span><span class="w"></span>

<span class="w">    </span><span class="n">map</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">Any</span>::<span class="n">type_id</span><span class="p">(</span><span class="o">&amp;</span><span class="n">id</span>::<span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">),</span><span class="w"> </span><span class="n">func</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">call_fn</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">&#39;static</span><span class="o">&gt;</span><span class="p">(</span><span class="n">map</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">HashMap</span><span class="o">&lt;</span><span class="n">TypeId</span><span class="p">,</span><span class="w"> </span><span class="nb">Box</span><span class="o">&lt;</span><span class="k">dyn</span><span class="w"> </span><span class="nb">FnMut</span><span class="p">(</span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="p">())</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">v</span>: <span class="nc">T</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">func</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">map</span><span class="p">.</span><span class="n">get_mut</span><span class="p">(</span><span class="o">&amp;</span><span class="n">Any</span>::<span class="n">type_id</span><span class="p">(</span><span class="o">&amp;</span><span class="n">id</span>::<span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">func</span><span class="p">(</span><span class="o">&amp;</span><span class="n">v</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="p">());</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;erased_functions: empty&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">erased_functions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">HashMap</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">insert_fn</span><span class="p">(</span><span class="n">erased_functions</span><span class="p">,</span><span class="w"> </span><span class="o">|</span><span class="n">v</span>: <span class="kp">&amp;</span><span class="kt">u32</span><span class="o">|</span><span class="w"> </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;u32: {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v</span><span class="p">));</span><span class="w"></span>
<span class="w">    </span><span class="n">insert_fn</span><span class="p">(</span><span class="n">erased_functions</span><span class="p">,</span><span class="w"> </span><span class="o">|</span><span class="n">v</span>: <span class="kp">&amp;</span><span class="nb">Box</span><span class="o">&lt;</span><span class="kt">u32</span><span class="o">&gt;|</span><span class="w"> </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;Box&lt;u32&gt;: {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v</span><span class="p">));</span><span class="w"></span>
<span class="w">    </span><span class="n">call_fn</span><span class="p">(</span><span class="n">erased_functions</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="k">u32</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">call_fn</span><span class="p">(</span><span class="n">erased_functions</span><span class="p">,</span><span class="w"> </span><span class="nb">Box</span>::<span class="n">new</span><span class="p">(</span><span class="mi">42</span><span class="k">u32</span><span class="p">));</span><span class="w"></span>
<span class="w">    </span><span class="n">call_fn</span><span class="p">(</span><span class="n">erased_functions</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;&amp;str&quot;</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="206290099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206290099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206290099">(Aug 07 2020 at 18:01)</a>:</h4>
<p>We can probably let today’s PRs land given that polymorphisation is still disabled.</p>



<a name="206290183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206290183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206290183">(Aug 07 2020 at 18:02)</a>:</h4>
<p>yeah <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> wouldn't have approved them otherwise</p>



<a name="206290209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206290209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206290209">(Aug 07 2020 at 18:02)</a>:</h4>
<p>I mostly think this is an issue of what we want to guarantee here</p>



<a name="206290244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206290244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206290244">(Aug 07 2020 at 18:02)</a>:</h4>
<p>But it might be worth discussing this in a compiler team meeting.</p>



<a name="206290248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206290248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206290248">(Aug 07 2020 at 18:02)</a>:</h4>
<p>llvm is already deduplicating functions</p>



<a name="206290327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206290327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206290327">(Aug 07 2020 at 18:03)</a>:</h4>
<p>hmm, yeah, I mostly think this is <code>T-lang</code> territory though</p>



<a name="206290502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206290502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206290502">(Aug 07 2020 at 18:04)</a>:</h4>
<p>That’s true, either way, I’ll make a note to raise this somewhere when I’m next doing rustc stuff.</p>



<a name="206343667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206343667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206343667">(Aug 08 2020 at 11:15)</a>:</h4>
<p>I thought a bit more about this and I think it would be good enough to have a warn by default lint when using types which are <code>MAY_POLYMORPHIZE</code> in <code>TypeId::of</code> and even potentially a deny by default lint when using <code>TypeId::of</code> of a type containing a polymorphized type.</p>



<a name="206343712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206343712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206343712">(Aug 08 2020 at 11:16)</a>:</h4>
<p><span class="user-mention" data-user-id="116107">@davidtwco</span> if you also think this is a good idea I can go ahead and implement this in the following weeks</p>



<a name="206343721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206343721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206343721">(Aug 08 2020 at 11:16)</a>:</h4>
<p>and then annoy <code>t-lang</code> and <code>wg-unsafe-code-guidelines</code></p>



<a name="206343782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206343782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206343782">(Aug 08 2020 at 11:18)</a>:</h4>
<p>That sounds reasonable to me but I think we’d want to raise it with the relevant teams first.</p>



<a name="206343793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206343793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206343793">(Aug 08 2020 at 11:18)</a>:</h4>
<p>yeah, I think a PR here is easy and would be good to show to potential fallout</p>



<a name="206343803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206343803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206343803">(Aug 08 2020 at 11:19)</a>:</h4>
<p>which is why I want to first open a PR and then ping lang</p>



<a name="206343913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206343913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206343913">(Aug 08 2020 at 11:23)</a>:</h4>
<p>That makes sense</p>



<a name="206343952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206343952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206343952">(Aug 08 2020 at 11:24)</a>:</h4>
<p>I’m fine with it.</p>



<a name="206364501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206364501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206364501">(Aug 08 2020 at 21:21)</a>:</h4>
<p>TypeId must remain globally unique for anything that has a different type, as any implementation of downcasting relies on that. While not many will be "downcast"ing function types, its still something that is currently supported and would be a breaking change.</p>



<a name="206364553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206364553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206364553">(Aug 08 2020 at 21:22)</a>:</h4>
<p>(downcasting is in turn typically implemented unsafely and is dependent on different <code>T</code>s in typesystem having different <code>TypeId</code>s)</p>



<a name="206364686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206364686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206364686">(Aug 08 2020 at 21:26)</a>:</h4>
<p>Furthermore, I don’t think a lint is feasible, unless we want to have SFINAE in Rust. Otherwise lint would likely have too many false positives due to not having sufficient information in typical use-cases of the construct (much like transmute currently fails <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=6cd9baa400ad4809114459496c3d405a">here</a>)</p>



<a name="206364918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206364918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206364918">(Aug 08 2020 at 21:33)</a>:</h4>
<p>Unless… I’m missing something?</p>



<a name="206364972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206364972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206364972">(Aug 08 2020 at 21:35)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=0fc2372645557cbbdc60f2d8d0e5be80">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=0fc2372645557cbbdc60f2d8d0e5be80</a> is probably the simpler reproducer.</p>



<a name="206365056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365056">(Aug 08 2020 at 21:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/216091-t-compiler.2Fwg-polymorphization/topic/TypeId.20guarantees/near/206364972">said</a>:</p>
<blockquote>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=0fc2372645557cbbdc60f2d8d0e5be80">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=0fc2372645557cbbdc60f2d8d0e5be80</a> is probably the simpler reproducer.</p>
</blockquote>
<p>The asserts fail when built with polymorphisation-enabled rustc today. I definitely get the sense that the issues we're seeing with polymorphisation are starting to get a bit too problematic.</p>



<a name="206365329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365329">(Aug 08 2020 at 21:44)</a>:</h4>
<p>I’m not super familiar with the implementation of polymorphization, at what level does this occur?</p>



<a name="206365348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365348">(Aug 08 2020 at 21:46)</a>:</h4>
<p>Conceptually I don’t feel like this specific problem is insurmountable, but its going to be extremely difficult to resolve if polymorphization loses type information somewhere early on during compilation.</p>



<a name="206365388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365388">(Aug 08 2020 at 21:46)</a>:</h4>
<p>During monomorphisation collection, we run <code>unused_generic_params</code> which determines which parameters are unused, then replace those unused indices in the substitution with the corresponding identity parameter, that results in more overlap in the mono item set and fewer copies of functions.</p>



<a name="206365405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365405">(Aug 08 2020 at 21:47)</a>:</h4>
<p>Oh I see, and we probably generate<code> TypeId</code>s during codegen too, after mono-collection...</p>



<a name="206365407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365407">(Aug 08 2020 at 21:47)</a>:</h4>
<p>Exactly</p>



<a name="206365408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365408">(Aug 08 2020 at 21:47)</a>:</h4>
<p>yeah</p>



<a name="206365410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365410">(Aug 08 2020 at 21:47)</a>:</h4>
<p>We could probably do that somewhere in MIR just fine.</p>



<a name="206365412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365412">(Aug 08 2020 at 21:47)</a>:</h4>
<p>It has been a long standing desire to handle some intrinsics in MIR.</p>



<a name="206365414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365414">(Aug 08 2020 at 21:47)</a>:</h4>
<p>we have to do it after mono-collection though</p>



<a name="206365415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365415">(Aug 08 2020 at 21:47)</a>:</h4>
<p>don't we</p>



<a name="206365455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365455">(Aug 08 2020 at 21:48)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/74717">#74717</a> made the relevant change so that using <code>TypeId</code> with polymorphised functions wouldn't ICE</p>



<a name="206365458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365458">(Aug 08 2020 at 21:48)</a>:</h4>
<p>hm.</p>



<a name="206365871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206365871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206365871">(Aug 08 2020 at 22:02)</a>:</h4>
<p>yeah this seems difficult, I was going to suggest that we could initially not polymorphize when there's an eventual call to <code>TypeId</code> or any body where dynamic objects are created, but that sounds difficult to achieve as well.</p>



<a name="206389819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206389819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206389819">(Aug 09 2020 at 10:50)</a>:</h4>
<p>I've filed <a href="https://github.com/rust-lang/rust/issues/75325">#75325</a> about this so we can keep track of this issue somewhere more permanent than Zulip.</p>



<a name="206389827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/TypeId%20guarantees/near/206389827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/TypeId.20guarantees.html#206389827">(Aug 09 2020 at 10:50)</a>:</h4>
<p>(feel free to assign yourself to this <span class="user-mention" data-user-id="216206">@lcnr</span> if you want to take point on working out what we should do about it)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>